package com.hsr.web.utils;

import com.baomidou.mybatisplus.core.toolkit.ClassUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

/**
 * @author tb
 * @create 2022-04-24 15:40
 * @remark
 */
public class FileUtil {
    public static String fileUpload(MultipartFile multipartFile,String uploadPath,String fileName) throws IOException {
        File dir = new File(uploadPath);
        if(!dir.exists()){
            dir.mkdirs();
        }
        String filePath = uploadPath + (StringUtils.hasLength(fileName)?fileName:multipartFile.getOriginalFilename());
        multipartFile.transferTo(new File(filePath));
        return filePath;
    }
}
